package ann;

public class Arc {

	private Link link;
	int from;
	int to;
	double weight;
	double weightDelta;
	double previousWeightDelta;
	
	public Arc(Link link, int from, int to, double weight) {
		this.link=link;
		this.from = from;
		this.to=to;
		this.weight = weight;
		weightDelta = 0.0;
		previousWeightDelta = 0.0;
	}

	public int getToIndex() {
		return to;
	}

	public double getWeight() {
		return weight;
	}

	public int getFromIndex() {
		return from;
	}

	public void incrementWeightDelta(double increment) {
		weightDelta += increment;
	}

	public void addWeightDelta() {
		weight += weightDelta + link.getMomentumRate()*previousWeightDelta;
		previousWeightDelta = weightDelta;
		weightDelta = 0.0;
	}

	public String toString(){
		return "Arc {"+from+"->"+to+", "+tr(weight)+"("+tr(weightDelta)+") }";
		
	}
	
	private double tr(double val){
		return ((int)(val*10000))/10000.0;
	}

	public void setWeight(double weight) {
		this.weight = weight;
		this.weightDelta = 0.0;
	}
}
